import {
  Entity,
  Column,
  ManyToOne,
  JoinColumn,
  Generated,
  PrimaryGeneratedColumn,
  PrimaryColumn,
} from 'typeorm';
import { BaseEntity } from './base.entity';
import { Dict } from './dict.entity';
import { ApiProperty } from '@nestjs/swagger';
import * as crypto from 'crypto';
@Entity()
export class DictItem extends BaseEntity {
  constructor() {
    super();
    this.id = crypto.randomBytes(8).toString('hex'); // 生成一个8字节（16个十六进制字符）的随机字符串作为id
  }
  @ApiProperty({
    required: false,
    description: '字典配置id',
  })
  @PrimaryColumn({ length: 225 })
  id: string;

  @ApiProperty({
    required: false,
    description: '字典项文本',
  })
  @Column({ nullable: true })
  itemText: string;

  @ApiProperty({
    required: false,
    description: '字典项值',
  })
  @Column({ nullable: true })
  itemValue: string;

  @ApiProperty({
    required: false,
    description: '描述',
  })
  @Column({ nullable: true })
  description: string;

  @ApiProperty({
    required: false,
    description: '排序',
  })
  @Column({ nullable: true })
  sortOrder: number;

  @ApiProperty({
    required: false,
    description: '状态（1启用 0不启用）',
  })
  @Column({ nullable: true })
  status: number;

  @ManyToOne(() => Dict, (dict) => dict.dictItems, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'dictId' })
  dict: Dict;
}
